<template>
  <div class="tenement-detail-info">
    <div class="header-info">
      <h3 :class="{ 'ml200': editCheck }"> </h3>
      <div>
        <el-button type="primary" @click="saveTenantDetail">保存</el-button>
      </div>
    </div>
    <div class="content-info">
      <div class="detail-info">
         <div class="info-left">
           <p class="info-left-top">效果预览</p>
          <div id="editor" class="info-left-prev" v-html="detailParams.detail" />
        </div>
        <Tinymce ref="editor" v-model="detailParams.detail" type="goods" class="info-right" :height="480" @changeVal="changeTinymce" />
      </div>
    </div>
  </div>
</template>
<script>
import Tinymce from '@/components/Tinymce'
import { getDetailByTenantId, getTenantDetailSave } from '@/api/tenement'
export default {
  components: {
    Tinymce
  },
  data() {
    return {
      cityArr: [],
      disableds: true,
      editCheck: false,
      detailParams: {
        type: 1,
        detail: ''
      }
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    saveTenantDetail() {
      getTenantDetailSave(this.detailParams).then(res => {
        this.$message.success('保存成功！')
        this.getInfo()
      })
    },
    getInfo() {
      getDetailByTenantId({type: 1}).then(response => {
        //console.log('>>>>>', JSON.stringify(response))
        if(response){
          this.detailParams = response
        }
      })
    },
    changeTinymce() {
      setTimeout(() => {
        const div = document.getElementById('editor')
        div.scrollTop = div.scrollHeight
      }, 1000)
    }
  }
}
</script>

<style lang="scss">
  .tenement-detail-info {
    .header-info {
      display: inline-flexbox;
      text-align: right;
      justify-content: right;
      width: 80%;
      .ml200 {
       margin-right: 200px;
       align-items: center;
      }
    }

    .content-info {
      display: flex;
      max-width: 100%;
      margin: 10px auto;
      .info-left {
        width: 320px;
        margin-right: 50px;
        border: 1px solid #dedede;
        .info-left-top {
          margin: 0;
          font-size: 14px;
          height: 40px;
          text-align: center;
          line-height: 40px;
          color: #333;
          background-color: #e5e5e5;
        }
        .info-left-prev {
          font-size: 12px;
          height: 450px;
          padding: 5px 10px;
          background-color: rgb(249, 249, 249);
          overflow-x: hidden;
          overflow-y: auto;
          img {
            width: 100%;
          }
        }
      }
      .detail-info {
        width: 800px;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        .info-right {
          flex: 1;
        }
      }
    }
  }
</style>
